package com.umeox.calculator;

import android.content.Context;
import android.graphics.Rect;
import android.text.Editable;
import android.text.Spanned;
import android.text.method.NumberKeyListener;
import android.util.AttributeSet;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;
import android.widget.ViewSwitcher;

class CalculatorDisplay extends ViewSwitcher {
    private static final char[] ACCEPTED_CHARS = "0123456789.+-*/−×÷()!%^".toCharArray();
    TranslateAnimation inAnimDown;
    TranslateAnimation inAnimUp;
    private int mMaxDigits = 10;
    TranslateAnimation outAnimDown;
    TranslateAnimation outAnimUp;

    enum Scroll {
        UP,
        DOWN,
        NONE
    }

    public CalculatorDisplay(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mMaxDigits = attrs.getAttributeIntValue(null, "maxDigits", 10);
    }

    public int getMaxDigits() {
        return this.mMaxDigits;
    }

    /* access modifiers changed from: protected */
    public void setLogic(Logic logic) {
        NumberKeyListener calculatorKeyListener = new NumberKeyListener() {
            /* class com.umeox.calculator.CalculatorDisplay.AnonymousClass1 */

            public int getInputType() {
                return 524289;
            }

            /* access modifiers changed from: protected */
            public char[] getAcceptedChars() {
                return CalculatorDisplay.ACCEPTED_CHARS;
            }

            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                return null;
            }
        };
        Editable.Factory factory = new CalculatorEditable.Factory(logic);
        for (int i = 0; i < 2; i++) {
            EditText text = (EditText) getChildAt(i);
            text.setBackground(null);
            text.setEditableFactory(factory);
            text.setKeyListener(calculatorKeyListener);
            text.setSingleLine();
        }
    }

    public void setOnKeyListener(OnKeyListener l) {
        getChildAt(0).setOnKeyListener(l);
        getChildAt(1).setOnKeyListener(l);
    }

    /* access modifiers changed from: protected */
    public void onSizeChanged(int w, int h, int oldW, int oldH) {
        this.inAnimUp = new TranslateAnimation(0.0f, 0.0f, (float) h, 0.0f);
        this.inAnimUp.setDuration(500);
        this.outAnimUp = new TranslateAnimation(0.0f, 0.0f, 0.0f, (float) (-h));
        this.outAnimUp.setDuration(500);
        this.inAnimDown = new TranslateAnimation(0.0f, 0.0f, (float) (-h), 0.0f);
        this.inAnimDown.setDuration(500);
        this.outAnimDown = new TranslateAnimation(0.0f, 0.0f, 0.0f, (float) h);
        this.outAnimDown.setDuration(500);
    }

    /* access modifiers changed from: package-private */
    public void insert(String delta) {
        EditText editor = (EditText) getCurrentView();
        editor.getText().insert(editor.getSelectionStart(), delta);
    }

    /* access modifiers changed from: package-private */
    public EditText getEditText() {
        return (EditText) getCurrentView();
    }

    /* access modifiers changed from: package-private */
    public Editable getText() {
        return ((EditText) getCurrentView()).getText();
    }

    /* access modifiers changed from: package-private */
    public void setText(CharSequence text, Scroll dir) {
        if (getText().length() == 0) {
            dir = Scroll.NONE;
        }
        if (dir == Scroll.UP) {
            setInAnimation(this.inAnimUp);
            setOutAnimation(this.outAnimUp);
        } else if (dir == Scroll.DOWN) {
            setInAnimation(this.inAnimDown);
            setOutAnimation(this.outAnimDown);
        } else {
            setInAnimation(null);
            setOutAnimation(null);
        }
        EditText editText = (EditText) getNextView();
        editText.setText(text);
        editText.setSelection(text.length());
        showNext();
    }

    /* access modifiers changed from: package-private */
    public int getSelectionStart() {
        return ((EditText) getCurrentView()).getSelectionStart();
    }

    /* access modifiers changed from: protected */
    public void onFocusChanged(boolean gain, int direction, Rect prev) {
        super.onFocusChanged(gain, direction, prev);
        if (!gain) {
            requestFocus();
        }
    }
}
